/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
    bool isSymmetric(TreeNode *tree1, TreeNode *tree2) {
        if (tree1==NULL && tree2==NULL) return true;
        if (((tree1==NULL) ^ (tree2==NULL)) || (tree1->val!=tree2->val)) return false;
        return isSymmetric(tree1->left, tree2->right) && isSymmetric(tree1->right, tree2->left);
    }
public:
    bool isSymmetric(TreeNode *root) {
        if (root==NULL) return true;
        return isSymmetric(root->left, root->right);
    }
};
